#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 5e5 + 10;
const int mod = 998244353;

int n,m,K,l[N],r[N],d[N],f[N],s,ans = 1,x[N],pre[N];

int upd(int x) { return x + (x >> 31 & mod); }

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,K = in,m = in; for(int i = 1;i <= m;i++) l[i] = in,r[i] = in,x[i] = in;
	for(int bit = 0;bit < K;bit++) {
		for(int i = 0;i <= n + 1;i++) pre[i] = d[i] = 0;
		for(int i = 1;i <= m;i++)
			if(x[i] >> bit & 1) d[l[i]]++,d[r[i] + 1]--;
			else pre[r[i]+1] = max(pre[r[i]+1],l[i]);
		f[0] = s = 1; int l = 0; 
		for(int i = 1;i <= n + 1;i++) {
			pre[i] = max(pre[i - 1],pre[i]); d[i] += d[i - 1];
			while(l < pre[i]) s = upd(s - f[l]),f[l] = 0,l++;
			if(d[i] == 0) f[i] = s, s = upd(s + f[i] - mod); else f[i] = 0;
		} 
		ans = (ll) ans * f[n + 1] % mod;
	}
	printf("%d\n",ans);
	return 0;
}
